package com.xinan.system.common;

import java.util.List;

import com.jfinal.core.BaseController;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * CommonController
 */
public class AddressController extends BaseController {

	/**
	 * 获取城市列表
	 */
	public void city() {
		List<Record> list = Db.find(" select id,province_code as code,province as name from tb_city ");
		Record root = new Record();
		root.set("id", 0);
		root.set("code", "");
		root.set("name", "请选择");
		list.add(0, root);
		renderJson(list);
	}

	/**
	 * 获取城市列表
	 */
	public void xian() {
		String city = getPara("city");
		String sql = " select id,city as citycode,city_name as name ,city_code as code from tb_xian where city = ? ";
		List<Record> list = Db.find(sql, city);
		if (list==null || list.size() <= 0) {
			Record root = new Record();
			root.set("id", 0);
			root.set("code", "");
			root.set("name", "请先选择县");
			list.add(0, root);
		} else {
			Record root = new Record();
			root.set("id", 0);
			root.set("code", "");
			root.set("name", "请选择");
			list.add(0, root);
		}
		renderJson(list);
	}

}
